<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>我的藏酒</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<include file="public/comm"/>
	</head>

	<body>
		<header class="mui-bar mui-bar1 mui-bar-nav fs_xl">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title fs_xl">赠送</h1>
		</header>
		<div class="mui-content fs_xl">
			<div class="zengs">
				<ul>
					<li class="mui-table-view-cell">
						<label><em>*</em>好友电话</label><input type="text" placeholder="输入号码" name="" id="phone" />
					</li>
					<li class="mui-table-view-cell">
						<label><em>*</em>好友账号</label><input type="text" placeholder="填写名称，限本平台用户" name="" readonly="readonly" id="nickname" to_uid="" />
					</li>
					<li class="mui-table-view-cell">
						<a id="check_bm" href="#middlePopover" class="mui-navigate-right"><label><em>*</em>选择编码</label><input readonly="readonly" type="text" placeholder="选择编码" name="" id="cellarnum" /></a>
					</li>
					<li class="mui-table-view-cell">
						<label>文字祝福</label><input type="text" placeholder="填写文字祝福语" name="" id="msg" />
					</li>
				</ul>
				<div class="tj_btn">
					<a class="fs_xl" id="give">确认</a>
				</div>
			</div>
			<div id="middlePopover" class="mui-popover">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll" id="xz_bm">
						<ul class="mui-table-view">
							<volist name="order_goodsinfo.bottle_num"  id="vo">
								<li class="mui-table-view-cell bm_xz">
									<a href="#">藏酒编码:<em>{$vo}</em><span class=""></span></a>
								</li>
							</volist>
						</ul>
					</div>
				</div>
				<div class="xz_btn fs_xl"><a class="fs_m">确认</a></div>
			</div>
		</div>
		<script type="text/javascript">
			mui.init();
			mui('.mui-scroll-wrapper').scroll();
			$(function(){
				$("#xz_bm li").toggle(function(){
					$(this).addClass("check");
					$(this).find("span").addClass("active");
					$(this).find("span").append('<i class="mui-icon mui-icon-checkmarkempty fs_xxi"></i>');
				},function(){
					$(this).removeClass("check");
					$(this).find("span").removeClass("active");
					$(this).find("i").remove();
				});
				$(".xz_btn").click(function(){
					var ar=[];
					$("#xz_bm li").each(function(){
						if($(this).hasClass("check")){
							ar.push($(this).find("em").text());
						}
					})
					$("#check_bm input").val(ar);
					mui('.mui-popover').popover("hide");
				})
			})
		</script>
		<script type="text/javascript">
		$(document).ready(function(){
			
			$("#phone").change(function(){
				//查询赠送账号是否存在
	 			var phone = $("#phone").val();
				if(!phone){
					alert("请输入赠送的账号");
					return false;
				}
				var to_uid = 0;
				$.ajax({
					type:"POST",
					url:"/Mobile/User/checkUserExit",
					data:{"phone":phone},
					dataType:"json",
					async:false,//同步操作
					success:function(date){
						if(date){
							to_uid = date.userid;
							$("#nickname").attr("to_uid",date.user_id);
							$("#nickname").val(date.nickname);
						}else{
							alert("赠送用户不存在");
							$("#phone").val(null);
							return false;
						}
					}
				});
				if(to_uid == 0){
					return false;
				}
			});
			
			$("#give").click(function(){
				
	//    			if({$orderinfo['user_id']} == to_uid){
	//    				alert("您不能将酒送给自己");
	//    				return false;
	//    			}
				//赠送藏酒
				var orderid = {$order_goodsinfo['order_id']};
				var rec_id = {$order_goodsinfo['rec_id']};
				var goods_id = {$order_goodsinfo['goods_id']};
				var type = 1;//赠酒
				var from_user_id = {$orderinfo['user_id']};
 				var to_user_id = $("#nickname").attr("to_uid");
 				if(!to_user_id){
 					alert("请输入正确的账号");
 					return false;
 				}
				var msg = $("#msg").val();
				
				//获取选中的藏酒编号
				var bottle_num = $("#cellarnum").val();
				if(bottle_num){
					var num = bottle_num.split(",").length;
				}else{
					alert("请选择藏酒编号");
					return false;
				}
				$.ajax({
					type:"POST",
					url:"/Mobile/User/cellar_oprate",
					data:{"order_id":orderid,"rec_id":rec_id,"goods_id":goods_id,"types":type,"from_user_id":from_user_id,"to_user_id":to_user_id,"bottle_num":bottle_num,"num":num,"msg":msg},
					dataType:"json",
					success:function(date){
						alert(date.msg);
						if(date.status){
							location.href="/mobile/User/cellar_list.html";
						}
					}
				});
			});
		});
</script>
	</body>

</html>